<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>基础知识</title>
	<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"" rel="stylesheet">
	<link href="https://cdn.bootcdn.net/ajax/libs/animate.css/3.2.3/animate.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="../../static/css/public.css" />
</head>
<body>
	<!--右边内容-->
	<div id="app" class="main animated fadeInRight">
		<div class="shadow">
			<div>
				<h4 >防抖函数</h4>
				<pre>
	const debounce = (cb, delay = 1000) => {
	  let timer = null;
	  return function (...args) {
		const context = this;
		if (timer) clearTimeout(timer);
		timer = setTimeout(() => {
		  cb.apply(context, args);
		  timer = null;
		}, delay);
	  }
	}
				</pre>
			</div>
			<div>
				<h4>节流函数(使用时间戳)</h4>
				<pre>
	const throttleUseTimeStamp = (cb, delay = 1000) => {
	  let startTime = Date.now();  
	　return function(...args) {      
	　　const context = this;                        
	　　const now = Date.now();           
	　　if (now - startTime >= delay) {
	      cb.apply(context, args);
	      startTime = Date.now();        
	　　}
	　} 
	}
				</pre>
			</div>
			<div>
			<h4>节流函数(使用定时器)</h4>
			<pre>
	const throttleUseTimer = (cb, delay) => {
	  let timer = null;
	  return function(...args) {
		const context = this;
		if (!timer) {
		  timer = setTimeout(() => {
			cb.apply(context, args);      
			timer = null;      
		  }, delay);  
		} 
	  }
	}
			</pre>
		</div>
		</div>
	</div>
	<!--页面加载进度条-->
	<script src="https://cdn.bootcdn.net/ajax/libs/pace/0.5.0/pace.min.js"></script>
</body>

</html>